package com.suning.sawp.web.controller;

import java.security.Principal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import com.suning.nsfuaa.employee.dto.EmployeeInfo;
import com.suning.sawp.constants.ClerkConstants;
import com.suning.sawp.constants.ErrorCodeConstants;
import com.suning.sawp.dto.common.ReturnMsg;
import com.suning.sawp.dto.customer.ArriveStoreCustListDto;
import com.suning.sawp.dto.customer.ClerkCustValidResult;
import com.suning.sawp.dto.customer.ClerkFollowCustRecord;
import com.suning.sawp.dto.customer.CustInfoDetailDto;
import com.suning.sawp.dto.customer.CustLabel;
import com.suning.sawp.dto.customer.PtyMemberRecordResponse;
import com.suning.sawp.dto.mainpush.StoreManDto;
import com.suning.sawp.dto.oga.bi.DevelopInfo;
import com.suning.sawp.dto.oga.bi.DevelopSaleDetail;
import com.suning.sawp.dto.oga.bi.DevelopingActivitySale;
import com.suning.sawp.dto.oga.bi.StaffCateGroup;
import com.suning.sawp.dto.oga.bi.StaffCateGroupModel;
import com.suning.sawp.dto.oga.bi.StaffDevelopInfo;
import com.suning.sawp.dto.oga.bi.StaffDevelopInfoWithSale;
import com.suning.sawp.dto.oga.bi.StaffDevelopSaleDetail;
import com.suning.sawp.dto.oga.bi.StaffDevelopingActivitySale;
import com.suning.sawp.intf.oga.ClerkCateGroupService;
import com.suning.sawp.intf.storeman.StoreManService;
import com.suning.sawp.po.customer.AOGBean;
import com.suning.sawp.po.customer.BaseTagGrade;
import com.suning.sawp.po.customer.ClerkCustInfo;
import com.suning.sawp.po.customer.ClerkOutAddrBean;
import com.suning.sawp.po.customer.LastSelEmpBean;
import com.suning.sawp.po.customer.OutAddrBean;
import com.suning.sawp.service.impl.customer.ClerkCustRelService;
import com.suning.sawp.service.impl.customer.PtyMemberRecordServiceImpl;
import com.suning.sawp.service.impl.oga.BIDevelopSaleServiceMonth;
import com.suning.sawp.service.impl.oga.BIDevelopingActivitySaleService;
import com.suning.sawp.service.impl.oga.OgaService;
import com.suning.sawp.service.impl.oga.bi.BIDevelopSaleService;
import com.suning.sawp.service.impl.oga.bi.BIDevelopStatsService;
import com.suning.sawp.service.util.BaseContants;
import com.suning.sawp.service.util.DJStringUtils;
import com.suning.sawp.service.util.DateUtils;
import com.suning.sawp.web.exception.MyGsonView;

/**
 * 
 * 〈店+会员业务〉<br>
 * 〈外拓等活动业务控制类〉
 *
 * @author 12061748
 * @see [相关类/方法]（可选）
 * @since [产品/模块版本] （可选）
 */
@Controller
@RequestMapping("/outGrow")
public class OutGrowController extends DjBaseController {
    private static final Logger LOGGER = LoggerFactory.getLogger(OutGrowController.class);

    @Autowired
    OgaService ogaService;
    @Autowired
    ClerkCustRelService clerkCustRelService;
    @Autowired
    StoreManService storeManService;
    @Autowired
    ClerkCateGroupService clerkCateGroupService;
    @Autowired
    BIDevelopStatsService biDevelopStatsServiceDay;
    @Autowired
    BIDevelopStatsService biDevelopStatsServiceWeek;
    @Autowired
    BIDevelopStatsService biDevelopStatsServiceMonth;
    @Autowired
    BIDevelopSaleService biDevelopSaleServiceDay;
    @Autowired
    BIDevelopSaleService biDevelopSaleServiceWeek;
    @Autowired
    BIDevelopSaleService biDevelopSaleServiceMonth;
    @Autowired
    BIDevelopingActivitySaleService biDevelopingActivitySaleService;
    
    /**
     * 企业会员服务
     */
    @Autowired
    PtyMemberRecordServiceImpl ptyMemberRecordService;

    /**
     * 
     * 功能描述: #1# 客户拓展数据统计（店员，督导，店长）<br>
     *
     * @param principal
     * @param queryType 0-昨日，1-本周，2-本月
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping(value = "bi/developStats.do", params = { "queryType=0" })
    public MyGsonView developStatsDay(Principal principal, @RequestParam(defaultValue = "-1") int offset) {
        ReturnMsg<DevelopInfo> ret = developStats(principal, biDevelopStatsServiceDay, offset);
        return setGsonView(ret);
    }

    @RequestMapping(value = "bi/developStats.do", params = { "queryType=1" })
    public MyGsonView developStatsWeek(Principal principal, @RequestParam(defaultValue = "-1") int offset) {
        ReturnMsg<DevelopInfo> ret = developStats(principal, biDevelopStatsServiceWeek, offset);
        return setGsonView(ret);
    }

    @RequestMapping(value = "bi/developStats.do", params = { "queryType=2" })
    public MyGsonView developStatsMonth(Principal principal, @RequestParam(defaultValue = "-1") int offset) {
        ReturnMsg<DevelopInfo> ret = developStats(principal, biDevelopStatsServiceMonth, offset);
        return setGsonView(ret);
    }

    private ReturnMsg<DevelopInfo> developStats(Principal principal, BIDevelopStatsService developStatsService,
            int offset) {
        ReturnMsg<DevelopInfo> ret = new ReturnMsg<DevelopInfo>();
        StoreManDto storeManDto = storeManService.queryStoreManAttachInfo(principal.getName());
        String storeCode = storeManDto.getStoreCode();
        DevelopInfo developInfo;
        if (ClerkConstants.STORE_KEEPER.equals(storeManDto.getPositionId())
                || ClerkConstants.SALE_GUIDE.equals(storeManDto.getPositionId())) {
            // 店长、督导
            developInfo = developStatsService.queryStoreDevelopInfo(storeCode, offset);
        } else {
            // 店员
            developInfo = developStatsService.queryStaffDevelopInfo(storeCode, principal.getName(), offset);
        }
        ret.setData(developInfo);
        return ret;
    }

    /**
     * #2# 品类下客户拓展数据详情（店长、督导）
     * 
     * @param principal
     * @param offset
     * @return
     */
    @RequestMapping(value = "bi/staffsDevelopStats.do", params = { "queryType=0" })
    public MyGsonView staffsDevelopStatsDay(Principal principal, @RequestParam String categoryCode,
            @RequestParam(defaultValue = "-1") int offset) {
        return setGsonView(staffsDevelopStats(principal, biDevelopStatsServiceDay, categoryCode, offset));
    }

    @RequestMapping(value = "bi/staffsDevelopStats.do", params = { "queryType=1" })
    public MyGsonView staffsDevelopStatsWeek(Principal principal, @RequestParam String categoryCode,
            @RequestParam(defaultValue = "-1") int offset) {
        return setGsonView(staffsDevelopStats(principal, biDevelopStatsServiceWeek, categoryCode, offset));
    }

    @RequestMapping(value = "bi/staffsDevelopStats.do", params = { "queryType=2" })
    public MyGsonView staffsDevelopStatsMonth(Principal principal, @RequestParam String categoryCode,
            @RequestParam(defaultValue = "-1") int offset) {
        return setGsonView(staffsDevelopStats(principal, biDevelopStatsServiceMonth, categoryCode, offset));
    }

    private ReturnMsg<List<StaffDevelopInfo>> staffsDevelopStats(Principal principal,
            BIDevelopStatsService developStatsService, String cateCode, int offset) {
        ReturnMsg<List<StaffDevelopInfo>> ret = new ReturnMsg<List<StaffDevelopInfo>>();
        StoreManDto storeManDto = storeManService.queryStoreManAttachInfo(principal.getName());
        String storeCode = storeManDto.getStoreCode();
        List<StaffDevelopInfo> staffDevelopInfos;
        if (ClerkConstants.STORE_KEEPER.equals(storeManDto.getPositionId())
                || ClerkConstants.SALE_GUIDE.equals(storeManDto.getPositionId())) {
            // 店长、督导
            if (null == cateCode) {
                // XXX 这边空字符串代表所有的品类
                throw new IllegalArgumentException("参数错误,需要传品类字段");
            }
            staffDevelopInfos = developStatsService.queryStoreCateDevelopInfo(storeCode, "".equals(cateCode) ? null
                    : cateCode, offset);
            ret.setData(new StaffDevelopInfoListDecorator(staffDevelopInfos));
        } else {
            ret.setError(
                    "Error",
                    String.format("%s of %s,%s,无权限操作", principal.getName(), storeManDto.getStoreCode(),
                            storeManDto.getPositionId()));
        }
        return ret;
    }

    /**
     * #3#销售转化数据额列表(门店、店员)
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "bi/developSaleStats.do")
    public MyGsonView developSaleStats(Principal principal, @RequestParam(defaultValue = "-1") int offset) {
        ReturnMsg<List<?>> ret = new ReturnMsg<List<?>>();
        StoreManDto storeManDto = storeManService.queryStoreManAttachInfo(principal.getName());
        String storeCode = storeManDto.getStoreCode();
        Map<String, Object> developingInfo = new JSONObject();
        Map<String, Object> arriveInfo = new JSONObject();
        Map<String, Object> recommendInfo = new JSONObject();
        if (ClerkConstants.STORE_KEEPER.equals(storeManDto.getPositionId())
                || ClerkConstants.SALE_GUIDE.equals(storeManDto.getPositionId())) {
            // 店长、督导
            try {
                developingInfo.put("type", ClerkCustInfo.CustSource.OUT_DEV);
                DevelopSaleDetail developing = ((BIDevelopSaleServiceMonth) biDevelopSaleServiceMonth)
                        .queryStoreDevelopingSaleInfo(storeCode, offset);
                developingInfo.putAll((JSONObject) JSON.toJSON(developing));

            } catch (Exception e) {
                LOGGER.error("staffId : {}, developSaleStats queryStoreDevelopingSaleInfo error", principal.getName(),
                        e);
                developingInfo.put("exception", e.getMessage());
            }

            try {
                arriveInfo.put("type", ClerkCustInfo.CustSource.ARRIVE_STORE);
                DevelopSaleDetail arrive = ((BIDevelopSaleServiceMonth) biDevelopSaleServiceMonth)
                        .queryStoreArriveSaleInfo(storeCode, offset);
                arriveInfo.putAll((JSONObject) JSON.toJSON(arrive));
            } catch (Exception e) {
                LOGGER.error("staffId : {}, developSaleStats queryStoreArriveSaleInfo error", principal.getName(), e);
                arriveInfo.put("exception", e.getMessage());
            }
            try {
                recommendInfo.put("type", ClerkCustInfo.CustSource.ACQ_RECOMMEND);
                DevelopSaleDetail recommend = ((BIDevelopSaleServiceMonth) biDevelopSaleServiceMonth)
                        .queryStoreRecommendSaleInfo(storeCode, offset);
                recommendInfo.putAll((JSONObject) JSON.toJSON(recommend));
            } catch (Exception e) {
                LOGGER.error("staffId : {}, developSaleStats queryStoreRecommendSaleInfo error", principal.getName(), e);
                recommendInfo.put("exception", e.getMessage());
            }

        } else {
            // 店员
            try {
                developingInfo.put("type", ClerkCustInfo.CustSource.OUT_DEV);
                DevelopSaleDetail developing = ((BIDevelopSaleServiceMonth) biDevelopSaleServiceMonth)
                        .queryStaffDevelopingSaleInfo(storeCode, principal.getName(), offset);
                developingInfo.putAll((JSONObject) JSON.toJSON(developing));
            } catch (Exception e) {
                LOGGER.error("staffId : {}, developSaleStats queryStaffDevelopingSaleInfo error", principal.getName(),
                        e);
                developingInfo.put("exception", e.getMessage());
            }

            try {
                arriveInfo.put("type", ClerkCustInfo.CustSource.ARRIVE_STORE);
                DevelopSaleDetail arrive = ((BIDevelopSaleServiceMonth) biDevelopSaleServiceMonth)
                        .queryStaffArriveSaleInfo(storeCode, principal.getName(), offset);
                arriveInfo.putAll((JSONObject) JSON.toJSON(arrive));
            } catch (Exception e) {
                LOGGER.error("staffId : {}, developSaleStats queryStaffArriveSaleInfo error", principal.getName(), e);
                arriveInfo.put("exception", e.getMessage());
            }

            try {
                recommendInfo.put("type", ClerkCustInfo.CustSource.ACQ_RECOMMEND);
                DevelopSaleDetail recommend = ((BIDevelopSaleServiceMonth) biDevelopSaleServiceMonth)
                        .queryStaffRecommendSaleInfo(storeCode, principal.getName(), offset);
                recommendInfo.putAll((JSONObject) JSON.toJSON(recommend));
            } catch (Exception e) {
                LOGGER.error("staffId : {}, developSaleStats queryStaffRecommendSaleInfo error", principal.getName(), e);
                recommendInfo.put("exception", e.getMessage());
            }
        }
        ret.setData(Lists.newArrayList(developingInfo, arriveInfo, recommendInfo));
        return setGsonView(ret);
    }

    /**
     * #4#（门店+店员）外拓活动统计列表
     */
    @RequestMapping(value = "bi/developingActivitySaleStats.do")
    public MyGsonView developingActivitySaleStats(Principal principal,
            @RequestParam(defaultValue = "10") Integer limit, @RequestParam(defaultValue = "0") Integer startIndex,
            @RequestParam String queryType) {
        ReturnMsg<List<DevelopingActivitySale>> ret = new ReturnMsg<List<DevelopingActivitySale>>();
        StoreManDto storeManDto = storeManService.queryStoreManAttachInfo(principal.getName());
        String storeCode = storeManDto.getStoreCode();
        boolean online = "0".equals(queryType);
        List<DevelopingActivitySale> developingActivitySales;
        if (ClerkConstants.STORE_KEEPER.equals(storeManDto.getPositionId())
                || ClerkConstants.SALE_GUIDE.equals(storeManDto.getPositionId())) {
            developingActivitySales = biDevelopingActivitySaleService.queryStoreDevelopingActivitySaleInfo(storeCode,
                    startIndex, limit, online);
        } else {
            developingActivitySales = biDevelopingActivitySaleService.queryStaffDevelopingActivitySaleInfo(storeCode,
                    principal.getName(), startIndex, limit, online);
        }
        ret.setData(developingActivitySales);
        return setGsonView(ret);
    }

    /**
     * #5#门店外拓活动统计详情（店长，督导）
     */
    @RequestMapping(value = "bi/developingActivitySaleStatsDetail.do")
    public MyGsonView developingActivitySaleStatsDetail(Principal principal, @RequestParam Integer activityId) {
        ReturnMsg<List<StaffDevelopingActivitySale>> ret = new ReturnMsg<List<StaffDevelopingActivitySale>>();
        StoreManDto storeManDto = storeManService.queryStoreManAttachInfo(principal.getName());
        String storeCode = storeManDto.getStoreCode();
        if (ClerkConstants.STORE_KEEPER.equals(storeManDto.getPositionId())
                || ClerkConstants.SALE_GUIDE.equals(storeManDto.getPositionId())) {
            List<StaffDevelopingActivitySale> sales = biDevelopingActivitySaleService
                    .queryStaffsDevelopingActivitySaleInfo(storeCode, activityId);
            StaffDevelopingActivitySale total = new StaffDevelopingActivitySale();
            total.setStaffName("总计");
            StaffDevelopingActivitySale avg = new StaffDevelopingActivitySale();
            avg.setStaffName("平均");
            ret.setData(new DevelopSaleDetailListDecorator<StaffDevelopingActivitySale>(sales, total, avg));
        } else {
            ret.setError(
                    "Error",
                    String.format("%s of %s,%s,无权限操作", principal.getName(), storeManDto.getStoreCode(),
                            storeManDto.getPositionId()));
        }
        return setGsonView(ret);
    }

    /**
     * #6#到店销售数据统计（店长督导） #8#到店销售数据统计（店员）
     * 
     */

    @RequestMapping(value = "bi/queryArriveSaleInfo.do", params = { "queryType=0" })
    public MyGsonView queryArriveSaleInfoDay(Principal principal, String categoryCode,
            @RequestParam(defaultValue = "-1") int offset) {
        return setGsonView(queryArriveSaleInfo(principal, biDevelopSaleServiceDay, categoryCode, offset));
    }

    @RequestMapping(value = "bi/queryArriveSaleInfo.do", params = { "queryType=1" })
    public MyGsonView queryArriveSaleInfoWeek(Principal principal, String categoryCode,
            @RequestParam(defaultValue = "-1") int offset) {
        return setGsonView(queryArriveSaleInfo(principal, biDevelopSaleServiceWeek, categoryCode, offset));
    }

    @RequestMapping(value = "bi/queryArriveSaleInfo.do", params = { "queryType=2" })
    public MyGsonView queryArriveSaleInfoMonth(Principal principal, String categoryCode,
            @RequestParam(defaultValue = "-1") int offset) {
        return setGsonView(queryArriveSaleInfo(principal, biDevelopSaleServiceMonth, categoryCode, offset));
    }

    private ReturnMsg<Object> queryArriveSaleInfo(Principal principal, BIDevelopSaleService developSaleService,
            String cateCode, int offset) {
        ReturnMsg<Object> ret = new ReturnMsg<Object>();
        StoreManDto storeManDto = storeManService.queryStoreManAttachInfo(principal.getName());
        String storeCode = storeManDto.getStoreCode();
        List<? extends Object> result;
        if (ClerkConstants.STORE_KEEPER.equals(storeManDto.getPositionId())
                || ClerkConstants.SALE_GUIDE.equals(storeManDto.getPositionId())) {
            if (null == cateCode) {
                // XXX 这边空字符串代表所有的品类
                throw new IllegalArgumentException("参数错误,需要传品类字段");
            }
            StaffDevelopSaleDetail total = new StaffDevelopSaleDetail();
            total.setStaffName("总计");
            StaffDevelopSaleDetail avg = new StaffDevelopSaleDetail();
            avg.setStaffName("平均");
            result = new DevelopSaleDetailListDecorator<StaffDevelopSaleDetail>(
                    developSaleService.queryStaffsArriveSaleInfo(storeCode, "".equals(cateCode) ? null : cateCode,
                            offset), total, avg);
        } else {
            result = developSaleService.queryStaffArriveSaleInfos(storeCode, principal.getName(), offset);
        }
        ret.setData(result);
        return ret;
    }

    /**
     * #9#熟人推荐销售数据统计（店员） #7#熟人推荐销售数据统计（店长督导）
     */
    @RequestMapping(value = "bi/queryRecommendSaleInfo.do", params = { "queryType=0" })
    public MyGsonView queryRecommendSaleInfoDay(Principal principal, String categoryCode,
            @RequestParam(defaultValue = "-1") int offset) {
        return setGsonView(queryRecommendSaleInfo(principal, biDevelopSaleServiceDay, categoryCode, offset));
    }

    @RequestMapping(value = "bi/queryRecommendSaleInfo.do", params = { "queryType=1" })
    public MyGsonView queryRecommendSaleInfoWeek(Principal principal, String categoryCode,
            @RequestParam(defaultValue = "-1") int offset) {
        return setGsonView(queryRecommendSaleInfo(principal, biDevelopSaleServiceWeek, categoryCode, offset));
    }

    @RequestMapping(value = "bi/queryRecommendSaleInfo.do", params = { "queryType=2" })
    public MyGsonView queryRecommendSaleInfoMonth(Principal principal, String categoryCode,
            @RequestParam(defaultValue = "-1") int offset) {
        return setGsonView(queryRecommendSaleInfo(principal, biDevelopSaleServiceMonth, categoryCode, offset));
    }

    private ReturnMsg<Object> queryRecommendSaleInfo(Principal principal, BIDevelopSaleService developSaleService,
            String cateCode, int offset) {
        ReturnMsg<Object> ret = new ReturnMsg<Object>();
        StoreManDto storeManDto = storeManService.queryStoreManAttachInfo(principal.getName());
        String storeCode = storeManDto.getStoreCode();
        List<? extends Object> result;
        if (ClerkConstants.STORE_KEEPER.equals(storeManDto.getPositionId())
                || ClerkConstants.SALE_GUIDE.equals(storeManDto.getPositionId())) {
            if (null == cateCode) {
                // XXX 这边空字符串代表所有的品类
                throw new IllegalArgumentException("参数错误,需要传品类字段");
            }
            StaffDevelopSaleDetail total = new StaffDevelopSaleDetail();
            total.setStaffName("总计");
            StaffDevelopSaleDetail avg = new StaffDevelopSaleDetail();
            avg.setStaffName("平均");
            result = new DevelopSaleDetailListDecorator<StaffDevelopSaleDetail>(
                    developSaleService.queryStaffsRecommendSaleInfo(storeCode, "".equals(cateCode) ? null : cateCode,
                            offset), total, avg);
        } else {
            result = developSaleService.queryStaffRecommendSaleInfos(storeCode, principal.getName(), offset);
        }
        ret.setData(result);
        return ret;
    }

    /**
     * #10#销售排行榜
     */
    @RequestMapping(value = "bi/queryStaffDevelopSaleLeaderBoardInfo.do", params = { "queryType=0" })
    public MyGsonView queryStaffDevelopSaleLeaderBoardInfoDay(Principal principal,
            @RequestParam(defaultValue = "-1") int offset) {
        return setGsonView(queryStaffDevelopSaleLeaderBoardInfo(principal, biDevelopSaleServiceDay, offset));
    }

    @RequestMapping(value = "bi/queryStaffDevelopSaleLeaderBoardInfo.do", params = { "queryType=1" })
    public MyGsonView queryStaffDevelopSaleLeaderBoardInfoWeek(Principal principal,
            @RequestParam(defaultValue = "-1") int offset) {
        return setGsonView(queryStaffDevelopSaleLeaderBoardInfo(principal, biDevelopSaleServiceWeek, offset));
    }

    @RequestMapping(value = "bi/queryStaffDevelopSaleLeaderBoardInfo.do", params = { "queryType=2" })
    public MyGsonView queryStaffDevelopSaleLeaderBoardInfoMonth(Principal principal,
            @RequestParam(defaultValue = "-1") int offset) {
        return setGsonView(queryStaffDevelopSaleLeaderBoardInfo(principal, biDevelopSaleServiceMonth, offset));
    }

    private ReturnMsg<Object> queryStaffDevelopSaleLeaderBoardInfo(Principal principal,
            BIDevelopSaleService developSaleService, int offset) {
        ReturnMsg<Object> ret = new ReturnMsg<Object>();
        StoreManDto storeManDto = storeManService.queryStoreManAttachInfo(principal.getName());
        String storeCode = storeManDto.getStoreCode();
        List<StaffDevelopInfoWithSale> result = developSaleService.queryStaffDevelopSaleLeaderBoardInfo(storeCode, 10,
                offset);
        ret.setData(result);
        return ret;
    }

    /**
     * 
     * 功能描述:会员首页数据 <br>
     * 〈我的客户数量和今日跟进数量〉
     *
     * @param principal
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping(value = "/queryMyCustInfo.do", produces = "application/json; charset=utf-8")
    public MyGsonView queryMyCustInfo(Principal principal) {
        Map<String, Object> result = new HashMap<String, Object>();
        MyGsonView gsonView = createGsonView();
        try {
            StoreManDto storeManDto = storeManService.queryStoreManAttachInfo(principal.getName());
            // 查询我的客户人数
            long myCustNum = clerkCustRelService.queryMyGrowCustNum(principal.getName(), storeManDto.getStoreCode());
            result.put("myCustNum", myCustNum);
            // 查询今日跟进人数
            long followNum = clerkCustRelService.queryTodayFollowCustNum(principal.getName());
            result.put("followNum", followNum);
            // 非会员数
            int noMemNum = clerkCustRelService.queryNoMemberNumByStaffId(principal.getName(),
                    storeManDto.getStoreCode());
            result.put("noMemNum", noMemNum);
            gsonView.addStaticAttribute(BaseContants.DATA, result);
        } catch (Exception e) {
            LOGGER.error("staffId : {}, queryMyCustInfo error", principal.getName(), e);
            setErrorMsg(gsonView, ErrorCodeConstants.ERR_0002);
        }
        return gsonView;
    }

    /**
     * 
     * 功能描述:查询外拓活动 <br>
     * 〈功能详细描述〉
     *
     * @param principal
     * @param queryType
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping(value = "/queryActList.do", produces = "application/json; charset=utf-8")
    public MyGsonView queryOutGradeActList(Principal principal, String queryType) {
        MyGsonView gsonView = createGsonView();
        try {
            StoreManDto storeManDto = storeManService.queryStoreManAttachInfo(principal.getName());

            List<AOGBean> list = ogaService.queryOutGrowActList(storeManDto.getStoreCode(), principal.getName(),
                    storeManDto.getPositionId(), queryType);
            gsonView.addStaticAttribute(BaseContants.DATA, list);
        } catch (Exception e) {
            LOGGER.error("staffId : {}, queryActList error", principal.getName(), e);
            setErrorMsg(gsonView, ErrorCodeConstants.ERR_0002);
        }
        return gsonView;
    }

    /**
     * 
     * 功能描述:通过活动id查询下面可见的任务列表 <br>
     * 〈功能详细描述〉
     *
     * @param principal
     * @param queryType
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping(value = "/queryAddrTaskList.do", produces = "application/json; charset=utf-8")
    public MyGsonView queryAddrTaskList(Principal principal, String actId) {
        MyGsonView gsonView = createGsonView();
        try {
            StoreManDto storeManDto = storeManService.queryStoreManAttachInfo(principal.getName());
            List<OutAddrBean> list = ogaService.queryOutAddrTaskList(storeManDto.getStoreCode(), principal.getName(),
                    storeManDto.getPositionId(), actId);
            gsonView.addStaticAttribute(BaseContants.DATA, list);
        } catch (Exception e) {
            LOGGER.error("staffId : {}, queryAddrTaskList error", principal.getName(), e);
            setErrorMsg(gsonView, ErrorCodeConstants.ERR_0002);
        }
        return gsonView;
    }

    /**
     * 
     * 功能描述:创建外拓活动 <br>
     * 〈功能详细描述〉
     *
     * @param principal
     * @param queryType
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping(value = "/saveOutGradeAct.do", produces = "application/json; charset=utf-8")
    public MyGsonView saveOutGradeAct(Principal principal, @RequestBody AOGBean aogBean) {
        MyGsonView gsonView = createGsonView();
        Map<String, Object> map = new HashMap<String, Object>();
        if (aogBean == null) {
            setErrorMsg(gsonView, ErrorCodeConstants.OUT_GRADE_ERR_E001);
            LOGGER.info("staffId : {}, saveOutGradeAct error ", principal.getName());
            return gsonView;
        }
        try {
            StoreManDto storeManDto = storeManService.queryStoreManAttachInfo(principal.getName());
            aogBean.setStaffCode(principal.getName());
            aogBean.setStoreCode(storeManDto.getStoreCode());
            aogBean.setStaffName(storeManDto.getStaffName());
            aogBean.setStartTime(aogBean.getStartTime() + " 00:00:00");
            aogBean.setEndTime(aogBean.getEndTime() + " 23:59:59");
            if (aogBean.getActId() == null) {
                // 判断当月已经创建了5条（同一店长和督导在一个自然月内最多只能新增5个外拓活动任务）
                long hasCreateNum = ogaService.countThisMonthCreateActNum(storeManDto.getStoreCode());
                if (hasCreateNum >= 5) {
                    setErrorMsg(gsonView, ErrorCodeConstants.OUT_GRADE_ERR_E004);
                    return gsonView;
                }
                aogBean.setCreateTime(DateUtils.getNowLongStr());
                Long actId = ogaService.createOutGrowAct(aogBean);
                map.put("actId", actId);
                gsonView.addStaticAttribute(BaseContants.DATA, map);
            } else {
                ogaService.updateOutGrowAct(aogBean);
                map.put("actId", aogBean.getActId());
                gsonView.addStaticAttribute(BaseContants.DATA, map);
            }
        } catch (Exception e) {
            LOGGER.error("staffId : {}, saveOutGradeAct error", principal.getName(), e);
            setErrorMsg(gsonView, ErrorCodeConstants.ERR_0002);
        }
        return gsonView;
    }

    /**
     * 
     * 功能描述:创建外拓活动的地点任务 <br>
     * 〈功能详细描述〉
     *
     * @param principal
     * @param queryType
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping(value = "/saveOutGradeAddrTask.do", produces = "application/json; charset=utf-8")
    public MyGsonView saveOutGradeAddrTask(Principal principal, @RequestBody OutAddrBean outAddrBean) {
        MyGsonView gsonView = createGsonView();
        if (outAddrBean == null) {
            setErrorMsg(gsonView, ErrorCodeConstants.OUT_GRADE_ERR_E001);
            LOGGER.info("staffId : {}, saveOutGradeAct error ", principal.getName());
            return gsonView;
        }
        if (CollectionUtils.isEmpty(outAddrBean.getClerkOutAddrTasks())) {
            LOGGER.info("staffId : {}, saveOutGradeAct error {}", principal.getName(),
                    ErrorCodeConstants.OUT_GRADE_ERR_E002);
            setErrorMsg(gsonView, ErrorCodeConstants.OUT_GRADE_ERR_E002);
            return gsonView;
        }
        // 新增场景判断是否地点任务达到了20
        if (outAddrBean.getTaskId() == null) {
            StoreManDto storeManDto = storeManService.queryStoreManAttachInfo(principal.getName());
            long num = ogaService.countOutAddrNumByActId(outAddrBean.getActId(), storeManDto.getStoreCode());
            if (num >= 20) {
                setErrorMsg(gsonView, ErrorCodeConstants.OUT_GRADE_ERR_E005);
                return gsonView;
            }
        }
        try {
            StoreManDto storeManDto = storeManService.queryStoreManAttachInfo(principal.getName());
            outAddrBean.setCreateTime(DateUtils.getNowLongStr());
            outAddrBean.setStaffCode(principal.getName());
            outAddrBean.setStoreCode(storeManDto.getStoreCode());
            outAddrBean.setStaffName(storeManDto.getStaffName());
            ogaService.saveOutAddrTask(outAddrBean);
            gsonView.addStaticAttribute(BaseContants.DATA, "");
        } catch (Exception e) {
            LOGGER.error("staffId : {}, saveOutGradeAct error", principal.getName(), e);
            setErrorMsg(gsonView, ErrorCodeConstants.ERR_0002);
        }
        return gsonView;
    }

    /**
     * 
     * 功能描述: 删除活动或者任务<br>
     * 〈功能详细描述〉
     *
     * @param principal
     * @param taskId
     * @param actId
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping(value = "/deleteActOrTask.do", produces = "application/json; charset=utf-8")
    public MyGsonView deleteActOrTask(Principal principal, String taskId, String actId) {
        MyGsonView gsonView = createGsonView();
        try {
            if (StringUtils.isNotBlank(actId)) {
                // 判断活动下是否拓展了会员，拓展了无法删除
                long num = clerkCustRelService.queryCustNum("", actId);
                if (num > 0) {
                    setErrorMsg(gsonView, ErrorCodeConstants.OUT_GRADE_ERR_E003);
                } else {
                    // 删除活动以及下面的所有任务和关系表
                    clerkCustRelService.deleteActByActId(actId);
                }
            }
            if (StringUtils.isNotBlank(taskId)) {

                // 判断任务下是否拓展了会员，拓展了无法删除
                long num = clerkCustRelService.queryCustNum(taskId, "");
                if (num > 0) {
                    setErrorMsg(gsonView, ErrorCodeConstants.OUT_GRADE_ERR_E003);
                } else {
                    StoreManDto storeManDto = storeManService.queryStoreManAttachInfo(principal.getName());
                    clerkCustRelService.deleteStoreTaskByTaskId(taskId, storeManDto.getStoreCode());
                }
            }
            gsonView.addStaticAttribute(BaseContants.DATA, "");
        } catch (Exception e) {
            LOGGER.error("staffId : {}, deleteActOrTask error", principal.getName(), e);
            setErrorMsg(gsonView, ErrorCodeConstants.ERR_0002);
        }
        return gsonView;
    }

    /**
     * 
     * 功能描述:查询门店下可选择的员工 <br>
     * 〈功能详细描述〉
     *
     * @param principal
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping(value = "/queryStoreEmpList.do", produces = "application/json; charset=utf-8")
    public MyGsonView queryStoreEmpList(Principal principal) {
        MyGsonView gsonView = createGsonView();
        try {
            List<EmployeeInfo> employees = storeManService.getClerksInStoreEx(principal.getName(),
                    "00000290,00000291,00000300,00010002,00010001,00000444");
            gsonView.addStaticAttribute(BaseContants.DATA, employees);
        } catch (Exception e) {
            LOGGER.error("staffId : {}, queryStoreEmpList error", principal.getName(), e);
            setErrorMsg(gsonView, ErrorCodeConstants.ERR_0002);
        }
        return gsonView;
    }

    /**
     * 
     * 功能描述:查询店长或者督导最近选择人 <br>
     * 〈功能详细描述〉
     *
     * @param principal
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping(value = "/queryLastSelEmpList.do", produces = "application/json; charset=utf-8")
    public MyGsonView queryLastSelEmpList(Principal principal) {
        MyGsonView gsonView = createGsonView();
        try {
            List<LastSelEmpBean> lastSelEmpList = ogaService.queryLastSelEmpList(principal.getName());
            gsonView.addStaticAttribute(BaseContants.DATA, lastSelEmpList);
        } catch (Exception e) {
            LOGGER.error("staffId : {}, queryLastSelEmpList error", principal.getName(), e);
            setErrorMsg(gsonView, ErrorCodeConstants.ERR_0002);
        }
        return gsonView;
    }

    /**
     * 
     * 功能描述:查询任务详情（店长和督导） <br>
     * 〈功能详细描述〉
     *
     * @param principal
     * @param taskId
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping(value = "/queryClerkTaskList.do", produces = "application/json; charset=utf-8")
    public MyGsonView queryTaskDetail(Principal principal, String taskId) {
        MyGsonView gsonView = createGsonView();
        try {
            StoreManDto storeManDto = storeManService.queryStoreManAttachInfo(principal.getName());
            String staffCode = storeManDto.getStaffId();
            Map<String, Object> map = new HashMap<String, Object>();
            List<ClerkOutAddrBean> clerkTasks = ogaService.queryClerkTaskList(taskId, storeManDto.getStoreCode());
            for (ClerkOutAddrBean clerkTask : clerkTasks) {
                if (staffCode.equals(clerkTask.getStaffCode())) {
                    map.put("ownerTask", clerkTask);
                    clerkTasks.remove(clerkTask);
                    break;
                }
            }
            String positionId = storeManDto.getPositionId();
            // 如果是店长或者督导则返回其他员工的任务信息
            if (ClerkConstants.STORE_KEEPER.equals(positionId) || ClerkConstants.SALE_GUIDE.equals(positionId)) {
                map.put("clerkTasks", clerkTasks);
            }

            gsonView.addStaticAttribute(BaseContants.DATA, map);
        } catch (Exception e) {
            LOGGER.error("staffId : {}, queryClerkTaskList error", principal.getName(), e);
            setErrorMsg(gsonView, ErrorCodeConstants.ERR_0002);
        }
        return gsonView;
    }

    /**
     * 
     * 功能描述:通过门店外拓地点任务id查询登录人的拓展会员列表 <br>
     * 〈功能详细描述〉
     *
     * @param principal
     * @param taskId
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping(value = "/queryOutGrowCustList.do", produces = "application/json; charset=utf-8")
    public MyGsonView queryOutGrowCustList(Principal principal, String taskId) {
        MyGsonView gsonView = createGsonView();
        try {
            List<CustInfoDetailDto> list = clerkCustRelService.queryOutGrowCustList(principal.getName(), taskId);
            gsonView.addStaticAttribute(BaseContants.DATA, list);
        } catch (Exception e) {
            LOGGER.error("staffId : {}, queryOutGrowCustList error", principal.getName(), e);
            setErrorMsg(gsonView, ErrorCodeConstants.ERR_0002);
        }
        return gsonView;
    }

    /**
     * 功能描述: 添加或者删除品类下人员<br>
     * 〈功能详细描述〉
     * 
     * @param principal
     * @param cateCode
     * @param cateName
     * @param groups
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping(value = "/handleClerkCateGroup.do", produces = "application/json; charset=utf-8")
    public MyGsonView handleClerkCateGroup(Model model, Principal principal, String cateCode, String cateName,
            StaffCateGroupModel groups) {
        MyGsonView gsonView = createGsonView();
        model.addAttribute("staffCateGroupModel", null);

        try {
            // 查询当前登录人员信息
            StoreManDto storeManDto = storeManService.queryStoreManAttachInfo(principal.getName());
            // 督导店长权限才能进行操作，非店长督导直接返回错误
            if (!(ClerkConstants.STORE_KEEPER.equals(storeManDto.getPositionId()) || ClerkConstants.SALE_GUIDE
                    .equals(storeManDto.getPositionId()))) {
                setErrorMsg(gsonView, ErrorCodeConstants.ERR_1013);
                return gsonView;
            }
            // 督导店长权限才能进行操作，进行操作，返回操作失败的人员信息
            List<StaffCateGroup> failedList = clerkCateGroupService.handleClerkCateGroup(storeManDto.getStoreCode(),
                    cateCode, cateName, groups.getStoreMans());
            gsonView.addStaticAttribute(BaseContants.DATA, failedList);
        } catch (Exception e) {
            LOGGER.error("staffId : {}, handleClerkCateGroup error", principal.getName(), e);
            setErrorMsg(gsonView, ErrorCodeConstants.ERR_0002);
        }
        return gsonView;
    }

    /**
     * 功能描述: 品类人员汇总列表<br>
     * 〈功能详细描述〉返回品类关系表中已经存在的品类关系及人员数量
     * 
     * @param principal
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping(value = "/queryStoreCateGroupsSize.do", produces = "application/json; charset=utf-8")
    public MyGsonView queryStoreCateGroupsSize(Principal principal) {
        MyGsonView gsonView = createGsonView();

        StoreManDto storeManDto = storeManService.queryStoreManAttachInfo(principal.getName());
        try {

            List<Map<String, Object>> result = clerkCateGroupService.queryStoreCateGroupsSize(storeManDto
                    .getStoreCode());
            gsonView.addStaticAttribute(BaseContants.DATA, result);
        } catch (Exception e) {
            LOGGER.error("staffId : {}, queryStoreCateGroupsSize error", principal.getName(), e);
            setErrorMsg(gsonView, ErrorCodeConstants.ERR_0002);
        }

        return gsonView;
    }

    /**
     * 功能描述: 品类下人员列表<br>
     * 〈功能详细描述〉 查询指定门店指定品类下的所有人员
     * 
     * @param principal
     * @param categoryCode
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping(value = "/queryStaffWithCateCode.do", produces = "application/json; charset=utf-8")
    public MyGsonView queryStaffWithCateCode(Principal principal, String categoryCode) {
        MyGsonView gsonView = createGsonView();

        StoreManDto storeManDto = storeManService.queryStoreManAttachInfo(principal.getName());

        try {
            List<Map<String, Object>> result = clerkCateGroupService.queryStaffWithCateCode(storeManDto.getStoreCode(),
                    categoryCode);
            gsonView.addStaticAttribute(BaseContants.DATA, result);

        } catch (Exception e) {
            LOGGER.error("staffId : {}, queryStaffWithCateCode error", principal.getName(), e);
            setErrorMsg(gsonView, ErrorCodeConstants.ERR_0002);
        }

        return gsonView;
    }

    /**
     * 
     * 功能描述: 校验此工号是否已经拓展了此手机对应客户<br>
     * 〈功能详细描述〉
     *
     * @param principal
     * @param mobile
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping("/validCustExist.do")
    public MyGsonView validCustExist(Principal principal, String mobile, String custSource) {
        ReturnMsg<ClerkCustValidResult> retMsg = clerkCustRelService.validCustExist(principal.getName(), mobile,
                custSource);
        return setGsonView(retMsg);
    }

    /**
     * 
     * 功能描述: 获取所有客户评级列表<br>
     * 〈功能详细描述〉
     *
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping("/getAllCustRates.do")
    public MyGsonView getAllCustRates() {
        ReturnMsg<List<BaseTagGrade>> retMsg = clerkCustRelService.getAllCustRates();
        return setGsonView(retMsg);
    }

    /**
     * 
     * 功能描述: 获取所有客户标签列表<br>
     * 〈功能详细描述〉
     *
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping("/getAllCustLabels.do")
    public MyGsonView getAllCustLabels() {
        ReturnMsg<List<CustLabel>> retMsg = clerkCustRelService.getAllCustLabels();
        return setGsonView(retMsg);
    }

    /**
     * 
     * 功能描述: 编辑客户资料信息<br>
     * 〈功能详细描述〉
     *
     * @param principal
     * @param detailDto
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping("/editCustInfo.do")
    public MyGsonView editCustInfo(Principal principal, @RequestBody CustInfoDetailDto detailDto) {
        ReturnMsg<String> retMsg = clerkCustRelService.editCustInfo(detailDto, principal.getName());
        return setGsonView(retMsg);
    }

    /**
     * 
     * 功能描述: 查询店员-客户关系详情<br>
     * 〈功能详细描述〉
     *
     * @param custRelId
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping("/queryCustInfo.do")
    public MyGsonView queryCustInfo(Long custRelId, Principal principal) {
        ReturnMsg<CustInfoDetailDto> retMsg = clerkCustRelService.queryCustInfoDetail(custRelId, principal.getName());
        return setGsonView(retMsg);
    }

    /**
     * 
     * 功能描述: 我的客户列表<br>
     * 〈功能详细描述〉
     *
     * @param principal
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping("/getMyCustInfoList.do")
    public MyGsonView getMyCustInfoList(Principal principal, String promoteDate) {
        ReturnMsg<List<CustInfoDetailDto>> retMsg = clerkCustRelService.getMyCustInfoList(principal.getName(),
                promoteDate);
        return setGsonView(retMsg);
    }

    /**
     * 
     * 功能描述: 到店客户列表<br>
     * 〈功能详细描述〉
     *
     * @param queryDate
     * @param principal
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping("/getArriveStoreCustList.do")
    public MyGsonView getArriveStoreCustList(String queryDate, Principal principal) {
        ReturnMsg<ArriveStoreCustListDto> retMsg = clerkCustRelService.getArriveStoreCustList(principal.getName(),
                queryDate);
        return setGsonView(retMsg);
    }

    /**
     * 到店客户查询新接口 功能描述: <br>
     * 〈功能详细描述〉
     *
     * @param queryDate
     * @param principal
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping("/getArriveStoreCustListNew.do")
    public MyGsonView getArriveStoreCustListNew(int index, int page, Principal principal) {
        if (index > 10000) {
            MyGsonView gsonView = createGsonView();
            LOGGER.error("staffId : {}, getArriveStoreCustListNew error", principal.getName());
            setErrorMsg(gsonView, ErrorCodeConstants.ERR_0001);
            return gsonView;
        }
        ReturnMsg<List<CustInfoDetailDto>> retMsg = clerkCustRelService.getArriveStoreCustListNew(principal.getName(),
                index, page);
        return setGsonView(retMsg);
    }

    /**
     * 
     * 功能描述: 获取熟人推荐客户列表<br>
     * 〈功能详细描述〉
     *
     * @param principal
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping("/getAcqRecommendCustList.do")
    public MyGsonView getAcqRecommendCustList(Principal principal) {
        ReturnMsg<List<CustInfoDetailDto>> retMsg = clerkCustRelService.getAcqRecommendCusts(principal.getName());
        return setGsonView(retMsg);
    }

    /**
     * 
     * 功能描述: 店员记录客户跟进记录<br>
     * 〈功能详细描述〉
     *
     * @param principal
     * @param followRemark
     * @param followResult
     * @param followType
     * @param nextFollowTime
     * @param custRelId
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping("/clerkFollowCust.do")
    public MyGsonView clerkFollowCust(Principal principal, String followRemark, String followResult,
            Integer followType, String nextFollowTime, Long custRelId) {
        ReturnMsg<String> retMsg = clerkCustRelService.clerkFollowCust(principal.getName(), followRemark, followResult,
                followType, nextFollowTime, custRelId);
        return setGsonView(retMsg);
    }

    /**
     * 
     * 功能描述: 查询跟进记录<br>
     * 〈功能详细描述〉
     *
     * @param custRelId
     * @param principal
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping("/queryCustFollowRecords.do")
    public MyGsonView queryCustFollowRecords(Long custRelId, Principal principal) {
        ReturnMsg<List<ClerkFollowCustRecord>> retMsg = clerkCustRelService.queryCustFollowRecords(custRelId,
                principal.getName());
        return setGsonView(retMsg);
    }

    /**
     * 
     * 功能描述: 设置（取消）重点客户<br>
     * 〈功能详细描述〉
     *
     * @param custRelId
     * @param opType
     * @param principal
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping("/setKeyCust.do")
    public MyGsonView setKeyCust(Long custRelId, Integer opType, Principal principal) {
        ReturnMsg<String> retMsg = clerkCustRelService.setKeyCust(custRelId, opType, principal.getName());
        return setGsonView(retMsg);
    }

    /**
     * 
     * 功能描述: 查询共享店员客户关系列表<br>
     * 〈功能详细描述〉
     *
     * @param principal
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping("/shareCustList.do")
    public MyGsonView shareCustList(Principal principal) {
        ReturnMsg<List<CustInfoDetailDto>> retMsg = clerkCustRelService.queryShareCustList(principal.getName());
        return setGsonView(retMsg);
    }

    /**
     * 
     * 功能描述: 分配共享客户关系给新的店员<br>
     * 〈功能详细描述〉
     *
     * @param custRelId
     * @param staffId
     * @param principal
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping("/assignShareCust.do")
    public MyGsonView assignShareCust(Long custRelId, String staffId, Principal principal) {
        ReturnMsg<String> retMsg = clerkCustRelService.assignShareCust(custRelId, staffId, principal.getName());
        return setGsonView(retMsg);
    }

    /**
     * 查询客户预约详情 功能描述: <br>
     * 〈功能详细描述〉
     *
     * @param principal
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping("/queryOrderCustInfo.do")
    public MyGsonView queryOrderCustInfo(Principal principal) {
        ReturnMsg<List<CustInfoDetailDto>> retMsg = clerkCustRelService.queryOrderCustInfo(principal.getName());
        return setGsonView(retMsg);
    }
    
    /**
     * 查询员工发展的企业会员记录
     * 功能描述: <br>
     * 〈功能详细描述〉
     *
     * @param principal
     * @param month
     * @param currIndex
     * @param pageSize
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping("/queryPtyMemberRecords.do")
    public MyGsonView queryPtyMemberRecords(Principal principal, String month, Integer currIndex, Integer pageSize) {
        // 月份参数
        Date monthParam = null;
        // 月份数据不为空时
        if (StringUtils.isNotBlank(month)) {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMM");
            try {
                monthParam = sdf.parse(StringUtils.trim(month));
            } catch (ParseException e) {
                LOGGER.error("queryPtyMemberRecords parse month find wrong.", e);
                ReturnMsg<String> retMsg = new ReturnMsg<String>();
                retMsg.setError(ErrorCodeConstants.ERR_0004, (Object)"month");
                return setGsonView(retMsg);
            }
        }
        ReturnMsg<PtyMemberRecordResponse> retMsg = ptyMemberRecordService.queryPtyMemberRecords(
                principal.getName(), DJStringUtils.initCurrIndex(currIndex), DJStringUtils.initPageSize(pageSize), monthParam);
        return setGsonView(retMsg);
    }

}